package xyz.zhno.upload.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * SHA256 工具类
 * @author zh_o
 * @date 2020-12-09
 */
public class SHA256Utils {

    public static void encrypt(java.io.File srcFile, java.io.File encFile) throws Exception {
        FileInputStream inputStream = new FileInputStream(srcFile);
        FileOutputStream outputStream = new FileOutputStream(encFile);
        MessageDigest messageDigest;
        messageDigest = MessageDigest.getInstance("SHA-256");
        int len;
        byte[] b = new byte[1024];
        while ((len = inputStream.read(b)) != -1) {
            messageDigest.update(b);
            outputStream.write(b, 0, len);
        }
    }

}
